<template>
	<view>
		<view style="background-color: #FFFFFF;">
			<view class="user_model">
				<view @click="toEdit()" style="width: 25%;">
					<image v-if="!user.avatarUrl" src="@/static/logo.png" mode="aspectFill" style="width: 60px;height: 60px;border-radius: 50%;"></image>
					<image v-else :src="user.avatarUrl" style="width: 60px;height: 60px;border-radius: 50%;"></image>
				</view>
				<view style="width: 75%;">
					<view @click="getUserProfile()" style="width: 100%;display: flex;">
						<view style="width: 75%;">
							<view class="nickName">{{user.nickName?user.nickName:'点击登录'}}</view>
						</view>
						<!-- <view @click="toEdit()" style="width: 25%;text-align: right;">
							<uni-icons type="compose" size="14"></uni-icons>
							<text style="font-size: 10px;">编辑信息</text>
						</view> -->
					</view>
					<view style="font-size: 12px;width: 100%;display: flex;">{{user.phone}}</view>
				</view>
			</view>
		</view>
		<view @click="toApplyList()" class="kuang">
			<view style="width: 100%;display: flex;margin: 5px auto;">
				<view style="width: 95%;">
					<uni-section title="报名记录" titleFontSize="16px" type="line"></uni-section>
				</view>
				<view style="width: 5%;line-height: 21px;">
					<uni-icons type="right" size="14"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/static/js/request.js'
	import data from '@/static/js/util.js'
	export default {
		data() {
			return {
				user: null,
			}
		},
		onShow() {
			let user = uni.getStorageSync('user');
			if(user != undefined && Object.keys(user).length > 0){
				this.user = user;
			}
		},
		onLoad(){
			
		},
		methods: {
			getUserProfile(){
				let _this = this;
				uni.getUserProfile({
					desc: '小程序展示用户头像与昵称',
					success(userRes) {
						uni.login({
							success(loginData) {
								api.login({
									nickName: userRes.userInfo.nickName,
									avatarUrl: userRes.userInfo.avatarUrl,
									code: loginData.code,
									anonymousCode: loginData.anonymousCode,
									state: 1
								}).then((res)=>{
									uni.setStorageSync('user',res.data)
									_this.user = res.data;
								})
							}
						})
					},
					fail(err) {
						console.log(err);
					}
				})
			},
			toApplyList(){
				uni.navigateTo({
					url: '/pages/applyList/applyList'
				})
			},
			
		}
	}
</script>

<style>
.user_model{
	width: 90%;
	height: 60px;
	padding: 10px 5%;
	display: flex;
	position: relative;
	border-radius: 20px 20px 0 0;
	z-index: 50;
}
.nickName{
	width: 100%;
	height: 35px;
	line-height: 35px;
	font-size: 16px;
}
</style>
